package cn.snsprj.authserver.util;

import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @author SKH
 * @date 2018-08-22 10:52
 **/
@Component
public class RedisUtil {


    @Autowired
    private RedisTemplate redisTemplate;

    /**
     *
     * Set the value and expiration timeout for key.
     *
     * @param key
     * @param value
     * @param timeout 单位秒
     */
    public void setEx(Object key, Object value, long timeout){
        redisTemplate.opsForValue().set(key, value, timeout, TimeUnit.SECONDS);
    }

    /**
     *
     * Get the value of key
     * @param key
     * @return
     */
    public Object get(Object key){
        return redisTemplate.opsForValue().get(key);
    }

    /**
     * 删除key
     *
     * @param key
     */
    public void delete(Object key){
        redisTemplate.delete(key);
    }
}
